package com.bsth.repository.schedule;

import com.bsth.entity.Line;
import com.bsth.entity.schedule.EmployeeConfigInfo;
import com.bsth.entity.schedule.TTInfo;
import com.bsth.repository.BaseRepository;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.data.jpa.repository.EntityGraph;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * Created by xu on 16/5/12.
 */
@Repository
public interface TTInfoRepository extends BaseRepository<TTInfo, Long> {

//    @EntityGraph(value = "ttInfo_xl", type = EntityGraph.EntityGraphType.FETCH)
    // 因为使用了in操作符，用 @EntityGraph会报错，升到hibernate 5.0.4就好了，暂时不用@EntityGraph
    // Hibernate ORMHHH-9230
    @Override
    Page<TTInfo> findAll(Specification<TTInfo> spec, Pageable pageable);

    @EntityGraph(value = "ttInfo_xl", type = EntityGraph.EntityGraphType.FETCH)
    @Query("select cc from TTInfo cc where cc.id=?1")
    TTInfo findOneExtend(Long aLong);

    @Query("select t from TTInfo t where t.xl = ?1 and t.isCancel = false")
    List<TTInfo> findInCanceledByXl(Line xl);
}
